package com.cuit.qx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuit.qx.bean.OperationLog;
import com.cuit.qx.dao.OperationLogMapper;
import com.cuit.qx.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:wjd
 * @Description: 日志类
 * @date:Created in 15:44 2020/9/15
 * @Modified By:
 */
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog> implements OperationLogService {

    @Autowired
    OperationLogMapper mapper;

    @Override
    public int insert(OperationLog operationLog) {

        return mapper.insert(operationLog);

    }

    @Override
    public List<OperationLog> getAllLogData(int pageNo, int pageSize) {

        IPage<OperationLog> userPage = new Page<>(pageNo, pageSize);//参数一是当前页，参数二是每页个数

        userPage = mapper.selectPage(userPage, null);

        return userPage.getRecords();
    }


    @Override
    public List<OperationLog> getConditionLogData(Integer pageNo, Integer pageSize, String operModul, String operType, String handlers, String startTime, String endTime) {

        List<OperationLog> conditionData = mapper.getConditionData(pageNo, pageSize, operModul, operType, handlers, startTime, endTime);
        return conditionData;
    }

    @Override
    public int getCount(String operModul, String operType, String handlers, String startTime, String endTime) {
        QueryWrapper<OperationLog> operationQuery = new QueryWrapper<OperationLog>();
        if(operModul !=null){
            operationQuery.eq("oper_modul",operModul);
        }
        if(operType != null){
            operationQuery.eq("oper_type",operType);
        }
        if(handlers != null){
            operationQuery.eq("handlers",handlers);
        }
        if(startTime != null){
            operationQuery.ge("oper_create_time",startTime);
        }
        if(endTime != null){
            operationQuery.le("oper_create_time",endTime);
        }
        int size = mapper.selectCount(operationQuery);
        return size;
    }

}
